#ifndef JZJ249350520MAINWINDOW_H
#define JZJ249350520MAINWINDOW_H

#include "opencv2/core/mat.hpp"
#include "qlabel.h"
#include <QMainWindow>
#include <QMediaPlayer>
#include <QAudioOutput>
#include <QVideoWidget>
#include <QSlider>
#include <QPushButton>
#include <QComboBox>
#include <QTimer>
#include <QImage>
#include <QAction>
#include <QProcess>  // 新增

QT_BEGIN_NAMESPACE
namespace Ui { class JZJ249350520MainWindow; }
QT_END_NAMESPACE

class JZJ249350520MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    JZJ249350520MainWindow(QWidget *parent = nullptr);
    ~JZJ249350520MainWindow();

private slots:
    void openImage();
    void saveImage();
    void toGray();
    void toBinary();
    void meanFilter();
    void gammaTransform();
    void edgeDetect();
    void showAbout();
    void openVideo();
    void toggleVideoPlayback();
    void updateVideoSlider(qint64 position);
    void onVideoSliderMoved(int position);
    void processCurrentFrame();
    void processVideoFrame();
    void applyFrameProcessing(int operation);
    void onSliderThresholdChanged(int);
    void on_btnRotateLeft_clicked();
    void on_btnRotateRight_clicked();
    void on_btnFlip_clicked();
    void on_btnReset_clicked();
    void on_sliderBrightness_valueChanged(int value);
    void on_sliderContrast_valueChanged(int value);
    void on_speedCombo_currentIndexChanged(int index);
    void detectFlames();
    void onFlameDetectionFinished();  // 新增：处理本地 API 结果

private:
    Ui::JZJ249350520MainWindow *ui;
    QImage imageOriginal;
    QImage imageCurrent;
    QMediaPlayer *mediaPlayer;
    QAudioOutput *audioOutput;
    QVideoWidget *videoWidget;
    QSlider *videoSlider;
    QTimer *frameTimer;
    QPushButton *playPauseButton;
    QComboBox *processMethodCombo;
    QComboBox *speedCombo;
    QImage lastProcessedFrame;
    double brightness;
    double contrast;
    QProcess *pythonProcess;  // 新增：用于调用 Python 脚本

    void setupVideoUI();
    cv::Mat applyMosaic(cv::Mat input, int blockSize = 10);
    void applyBrightnessContrast();
    void showImage(const QImage &img);
    bool isImageLoaded() const;
    void showMsgBox(const QString &title, const QString &info);
    QLabel* imageLabel();
    QSlider* sliderThreshold();
    void closeEvent(QCloseEvent *event);
};

#endif // JZJ249350520MAINWINDOW_H
